//
//  InputMailBillViewController.swift
//  KaMengApplication
//
//  Created by DUONIU_MAC on 2019/1/11.
//  Copyright © 2019年 DUONIU_MAC. All rights reserved.
//

import UIKit

class InputMailBillViewController: BillRootViewController {
    
    fileprivate let accountView = InputView.init(inputStyle: .account) //邮箱账号
    fileprivate let passwordView = InputView.init(inputStyle: .password) //邮箱密码

    override func viewDidLoad() {
        super.viewDidLoad()

        self.title = mailBill
        addSubView()

    }
    
    //MARK: 添加子视图
    fileprivate func addSubView() {
        
//        accountView.textField.text = "tianbao_lin@163.com"
        accountView.placeholder = inputMail
        accountView.textField.keyboardType = .default
        self.view.addSubview(accountView)
        
//        passwordView.textField.text = "LinTianbao"
        passwordView.placeholder = inputMailPassWord
        passwordView.textField.isSecureTextEntry = true
        self.view.addSubview(passwordView)
        
        let signInButton = UIButton()
        signInButton.backgroundColor = UIColor.red
        signInButton.setTitle(signIn_title, for: .normal)
        signInButton.titleLabel?.font = UIFont.systemFont(ofSize: RATIO(maxNum: 16))
        signInButton.layer.cornerRadius = RATIO_H(maxNum: 20)
        signInButton.layer.masksToBounds = true
        signInButton.addTarget(self, action: #selector(signInMail), for: .touchUpInside)
        self.view.addSubview(signInButton)
        
        accountView.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(RATIO(maxNum: 20))
            make.right.equalToSuperview().offset(RATIO(maxNum: -20))
            make.height.equalTo(RATIO_H(maxNum: 50))
            make.top.equalToSuperview().offset(RATIO_H(maxNum: 150))
        }
        
        passwordView.snp.makeConstraints { (make) in
            make.left.right.height.equalTo(accountView)
            make.top.equalTo(accountView.snp.bottom).offset(RATIO_H(maxNum: 20))
        }
        
        signInButton.snp.makeConstraints { (make) in
            make.top.equalTo(passwordView.snp.bottom).offset(RATIO_H(maxNum: 50))
            make.centerX.equalToSuperview()
            make.width.equalTo(RATIO(maxNum: 300))
            make.height.equalTo(RATIO_H(maxNum: 40))
        }
    }
    
    //MARK: 邮箱登录
    @objc fileprivate func signInMail() {
        
        if accountView.text == "" {
            KMTool.showText(_text: inputMail)
            return
        }
        
        if passwordView.text == "" {
            KMTool.showText(_text: inputMailPassWord)
            return
        }
        
        let urlStr = url_getMailBill + "/email/\(accountView.text)/password/\(passwordView.text)/etoken/"
        
        KMTool.waiting()
        KMTool.requestGetData(URLString: urlStr, parameters: nil, success: { (data) in
            KMTool.stop()
            
            
            
        }) {
            KMTool.stop()
        }
    }
    

}
